<#include "../common/header.htm">
<div class="content-wrapper">
	<section class="content-header">
		<ol class="breadcrumb">
			<li><a href="${ctx}/">首页</a></li>
			<li class="active"><a href="${ctx}/questionnaire/approvelist">待审核</a></li>
		</ol>
	</section>
	<section class="content">
		<form action="${ctx}/questionnaire/approvelist" method="get" class="form-inline">
			<div class="box">
				<div class="box-header">
					<div class="row">
						<div class="col-sm-9">
							<div class="col-sm-2 form-group">
								<label>状态：</label>
								<select  class="form-control" name="state">
									<option value="all">全部</option>
									<option value="0" <#if RequestParameters['state']?? && RequestParameters['state']=='0' > selected="selected" </#if>>待同步</option>
									<option value="1" <#if RequestParameters['state']?? && RequestParameters['state']=='1' > selected="selected" </#if>>同步中</option>
									<option value="2" <#if RequestParameters['state']?? && RequestParameters['state']=='2' > selected="selected" </#if>>已同步</option>
									<option value="3" <#if RequestParameters['state']?? && RequestParameters['state']=='3' > selected="selected" </#if>>同步失败</option>
								</select>
							</div>
							<div class="col-sm-3" >
								<label>关键字：</label>
								<input name="keyword" type="text" class="form-control" value="${keyword!}" placeholder="公司名称/话术名称" />
							</div>
							<div class="col-sm-1">
								<input type="button" class="btn btn-default btn-search" onclick="query();" value="查询" />
							</div>
						</div>
					</div>
				</div>
				<div class="box-body">
					<table class="table table-hover table-bordered table-striped">
						<thead>
							<tr>
								<th style="width:5%;">序号</th>
								<th>代理商</th>
								<th>客户经理</th>
								<th>公司</th>
								<th>话术名称</th>
								<th>类型</th>
								<th>提交人</th>
								<th>提交时间</th>
								<th>录音状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<#list page.content as c>
								<tr>
									<td>${page.size * page.number+c_index+1}</td>
									<td>${c.agentsName!}</td>
									<td>${c.accountManagerName!}</td>
									<td><a href="javascript:void(0);" onclick="viewCompany('${c.companyId!}')">${c.companyName!}</a></td>
									<td><a href="javascript:void(0);" onclick="toEdit('${c.companyId!}','${c.id!}','${c.scriptId!}')">${c.title!}</a></td>
									<#if c.industryType?? && dict["${c.industryType}"]?? >
										<td>${dict["${c.industryType}"]!}</td>
									<#else>
										<td></td>
									</#if>
									<td>${c.createUserName!}</td>
									<td>${c.updateTime!}</td>
									<td>
										<#if c.audioState?? && c.audioState==1>
											同步中
										<#elseif c.audioState?? && c.audioState==2>
											同步成功
										<#elseif c.audioState?? && c.audioState==3>
											同步失败
										<#else>
											待同步
										</#if>
									</td>
									<td>
										<a href="javascript:void(0)" onclick="loginfo('${c.id!}','${c_index!}','${page.number!}')" class="oper">审核</a>
									</td>
								</tr>
							</#list>
						</tbody>
					</table>
					<#include "../common/page.htm">
				</div>
			</div>
		</form>
	</section>
</div>

<script type="text/javascript">
    sessionStorage.sum="${page.totalElements}"; //把每次查询到的数据放到sessionStorage，审批的时候上一条下一条要用到
	var win;
	var outPath = "${redirectUri}";
	var flag=0;
	//查询
	function query() {
		$(":input[name='pageNumber']").val(0);
		$("form").submit();
	}
	//编辑话术内容
	function toEdit(companyId,naireId,scriptId){
		var url = "${ctx}/login/sysOutLogin";
		$.ajax({
			url : url,
			type : 'post',
			dataType : 'json',
			data : {"companyId":companyId},
			success : function(data) {
				if(data!=null){
					var sign = data.sign;
					var timestamps = data.timestamps;
					var newUrl = outPath+"login/sysOutLogin.action?_clientType=wap&sign="+sign+"&timestamps="+timestamps+"&companyId="+companyId+"&naireId="+naireId+"&scriptId="+scriptId+"&requestType=questionnaire";
					if(win){
						win.close();
					}
					window.open(newUrl,"_blank");
				}else{
					bootbox.alert("跳转失败,请稍后重试!");
				}
			}
		});
	}
	
	//查看企业详情	
	function viewCompany(companyId){
		var url = "${ctx}/login/sysOutLogin";
		$.ajax({
			url : url,
			type : 'post',
			dataType : 'json',
			data : {"companyId":companyId},
			success : function(data) {
				if(data!=null){
					var sign = data.sign;
					var timestamps = data.timestamps;
					var newUrl = outPath+"login/sysOutLogin.action?_clientType=wap&sign="+sign+"&timestamps="+timestamps+"&companyId="+companyId+"&requestType=index";
					if(win){
						win.close();
					}
					window.open(newUrl,"_blank");
				}else{
					bootbox.alert("跳转失败,请稍后重试!");
				}
			}
		});
	}
	

	//同步录音
	function syncVoxFile(naireId){
		var url = "${ctx}/questionnaire/updateAudioState";
		var param = {
				"id":naireId,
				"audioState":1
			};
		$.ajax({
			url:url,
			type:'POST',
			data:param,
			dataType:'text',
			async:false,
			success:function(data){
				if(data=="success"){
					bootbox.alert("操作成功,请等待...",function(){
						window.location.reload();
					});
				}else if(data=="1"){
					bootbox.alert("无法同步语音,请先配置网关通道或部署语音同步程序!");
				}else{
					bootbox.alert("同步语音失败,请稍后重试!");
				}
			}
		});
	}
	
	//取消同步录音
	function desyncVoxFile(naireId){
		var url = "${ctx}/questionnaire/updateAudioState";
		var param = {
				"id":naireId,
				"audioState":0
			};
		$.ajax({
			url:url,
			type:'POST',
			data:param,
			dataType:'text',
			async:false,
			success:function(data){
				if(data=="success"){
					bootbox.alert("操作成功!",function(){
						window.location.reload();
					});
				}else{
					bootbox.alert("操作失败,请稍后重试!");
				}
			}
		});
	}
	
	//审核方法
	function loginfo(id,index,page){
	    var state=$("select[name='state']").val();
        var keyword=$("input[name='keyword']").val();
        window.location.href="${ctx}/questionnaire/loginfo?id="+id+"&index="+index+"&page="+page+"&state="+state+"&keyword="+keyword+"&from=未审核";
	}
</script>
<#include "../common/footer.htm">